package com.hanfengyi.feign.fallback;

import com.hanfengyi.feign.RedisFeignClient;
import com.hanfengyi.hrm.AjaxResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * User: Han
 * Date: 2020/2/21
 * Time: 19:27
 * Description:
 */
@Component
public class CourseFeignFallbackFactory implements FallbackFactory<RedisFeignClient> {
    @Override
    public RedisFeignClient create(Throwable throwable) {
        return new RedisFeignClient() {
            @Override
            public AjaxResult set(String key, String value) {
                return AjaxResult.me().setSuccess(false)
                        .setMessage("发生了一点小问题:["+throwable.getMessage()+"]");
            }

            @Override
            public AjaxResult get(String key) {
                return AjaxResult.me().setSuccess(false)
                        .setMessage("发生了一点小问题:["+throwable.getMessage()+"]");
            }

            @Override
            public AjaxResult setex(String key, int seconds, String value) {
                return AjaxResult.me().setSuccess(false)
                        .setMessage("发生了一点小问题:["+throwable.getMessage()+"]");
            }
        };
    }
}